package com.woniuxy.woniuticket.financemodule.service.impl;

import com.woniuxy.woniuticket.financemodule.dao.CinemaAccountDAO;

import com.woniuxy.woniuticket.financemodule.service.CinemaAccountService;
import com.woniuxy.woniuticket.pojo.CinemaAccount;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * Created by Wu xianbo on 2019/6/1
 */

@Service
public class CinemaAccountServiceImpl implements CinemaAccountService {

    @Resource
    private CinemaAccountDAO cinemaAccountDAO;

    //账户进账
    @Override
    public int increaseMoney(BigDecimal money) {
        return cinemaAccountDAO.increaseMoney(money);
    }

    //账户退款
    @Override
    public int decreaseMoney(BigDecimal money) {
        return cinemaAccountDAO.decreaseMoney(money);
    }

    //查询账户余额
    @Override
    public CinemaAccount findAccountBalance() {
        return cinemaAccountDAO.findAccountBalance();
    }

    //缴纳年费
    @Transactional
    @Override
    public int payFee(BigDecimal money) {
        //查询当前账户余额
        BigDecimal accountBalance = cinemaAccountDAO.findAccountBalance().getAcocuntmoney();
        if(accountBalance.compareTo(money)<0){
            System.out.println("当前账户余额不足");
            return  -1;
        }
        return cinemaAccountDAO.payFee(money);
    }
}
